package cn.z2huo.leetcode.problem.NO_0007;

import java.util.Scanner;


public class ReverseInt {
	public int reverse(int demo) {
		int result = 0;
		String str = String.valueOf(demo);
		char[] ch = null;
		char[] ch_new = new char[str.length()];
		ch = str.toCharArray();
		
		for(int j=0; j<ch.length; j++) {
			System.out.println(ch[j]);
		}
		if(demo<0) {
			System.out.println("输入的为负数");
			for(int i=1; i<ch.length; i++) {
				ch_new[i] = ch[ch.length-i];
			}
			ch_new[0] = '-';
		}else if(demo>0){
			System.out.println("输入的是正数");
			for(int i=0; i<ch.length; i++) {
				ch_new[i] = ch[ch.length-1-i];
			}
		}
		str = String.valueOf(ch_new);
		result = Integer.parseInt(str);
		return result;
	}
	
	public static void main(String[] args) {
		int demo = 0;
		ReverseInt ri = new ReverseInt();
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入您想要进行反转的整数（可以是负数）:");
		demo = sc.nextInt();
		System.out.println("得到的结果是"+ri.reverse(demo));
		sc.close();
	}
}
